import requests
import json
import asyncio
import aiohttp

# url = 'https://api.web.360kan.com/v1/rank?cat=1'
#
# response = requests.get(url)
# json_data = response.json()
# for data in json_data['data']:
#     print(data['title'], data['description'])


# async def fun(session, url):
#     async with aiohttp.ClientSession() as session:
#         async with session.get(url) as response:
#             response =  await response.json()
#             print(response)
#
# async def main():
#     async with aiohttp.ClientSession() as session:
#         urls = [f'https://api.web.360kan.com/v1/rank?cat={cat}' for cat in range(1, 7)]
#         tasks = [fun(session, url) for url in urls]
#         await asyncio.gather(*tasks)
#
# asyncio.run(main())


import threading


def thread_fun(url):
    resp = requests.get(url)
    print(threading.current_thread().name,resp.json())


def main():
    urls = [f'https://api.web.360kan.com/v1/rank?cat={cat}' for cat in range(1, 7)]
    threads = []
    for url in urls:
        t = threading.Thread(target=thread_fun, name=f'thread-{url}', args=(url,))
        t.start()
        threads.append(t)
    for i in threads:
        i.join()


if __name__ == '__main__':
    main()
